package com.ctshk.sapp.order.custom.controller;


import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.validation.Valid;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ctshk.common.utils.DateUtil;
import com.ctshk.rpc.order.custom.excel.ExcelData;
import com.ctshk.rpc.order.custom.excel.ExportExcelUtils;
import com.ctshk.rpc.order.custom.req.tourist.*;
import com.ctshk.rpc.order.custom.vo.ExcelTemp;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.bind.annotation.*;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.custom.dto.tourist.CustomGroupTouristInfoDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristGroupDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristInfoDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristInfoDetailDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristInfoListCollectionDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristInfoPreviewInvoiceDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristNameListDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristRoomDTO;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristRoomGroupDTO;
import com.ctshk.rpc.order.custom.req.order.CustomOrderIdReq;
import com.ctshk.rpc.order.custom.req.schedule.TripScheduleInfoReq;
import com.ctshk.rpc.order.custom.service.ICustomizedOrderTouristInfoService;
import com.ctshk.sapp.order.custom.excel.CustomOrderTouristInfoExcelAddListener;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 游客信息 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
@Api(value="旅客信息", tags="旅客信息")
@RestController
@Slf4j
@RequestMapping("/customized-order-tourist-info")
public class CustomizedOrderTouristInfoController extends BaseController {

    @DubboReference
    private ICustomizedOrderTouristInfoService orderTouristInfoService;


    @ApiOperation(value = "列表", notes = "旅客信息列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅客信息列表", operDesc = "旅客信息列表")
    @PostMapping("/list")
    public Result<PageResponse<CustomOrderTouristInfoDTO>> list(@RequestBody @Valid CustomOrderIdReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return Result.success(orderTouristInfoService.list(req));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "编辑", notes = "编辑旅客信息（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "编辑旅客信息", operDesc = "编辑旅客信息")
    @PostMapping("/edit")
    public Result edit(@RequestBody @Valid CustomOrderTouristInfoEditReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.edit(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "详情", notes = "旅客详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "旅客详情", operDesc = "旅客详情")
    @PostMapping("/detail")
    public Result<CustomOrderTouristInfoDetailDTO> detail(@RequestBody @Valid CustomOrderTouristIdReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.detail(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "删除", notes = "删除旅客（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.DELETE, operTitle = "删除旅客", operDesc = "删除旅客")
    @PostMapping("/delete")
    public Result delete(@RequestBody @Valid CustomOrderTouristIdReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.delete(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "添加", notes = "添加旅客（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "添加旅客", operDesc = "添加旅客")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid CustomOrderTouristInfoAddReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.add(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "校验是否可添加", notes = "校验是否可添加（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "校验是否可添加", operDesc = "校验是否可添加")
    @PostMapping("/check-add")
    public Result<Boolean> checkAdd(@RequestBody @Valid TouristInfoCheckAddReq req) {
        try {
            return orderTouristInfoService.checkAdd(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "收款列表", notes = "收款列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收款管理", operDesc = "收款管理")
    @PostMapping("/list/collection")
    public Result<PageResponse<CustomOrderTouristInfoListCollectionDTO>> listCollection(@RequestBody @Valid CustomOrderIdReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return Result.success(orderTouristInfoService.listCollection(req));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="团期详情-订单收款明细", notes="团期详情-订单收款明细(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "团期详情-订单收款明细", operDesc = "团期详情-订单收款明细")
    @PostMapping("/schedule-recive-list")
    public Result<List<CustomOrderTouristInfoListCollectionDTO>> detailReciveList(@RequestBody @Valid TripScheduleInfoReq req) {
        try {
            List<CustomOrderTouristInfoListCollectionDTO> dto = orderTouristInfoService.reciveListBySchedule(req);
            return Result.success(dto);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "打印發票预览", notes = "打印發票预览（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "打印發票预览", operDesc = "打印發票预览")
    @PostMapping("/preview/invoice")
    public Result<CustomOrderTouristInfoPreviewInvoiceDTO> previewInvoice(@RequestBody @Valid CustomOrderTouristInfoPreviewInvoiceReq req) {
        try {
            return orderTouristInfoService.previewInvoice(req,getCurrentUser(getRequest()));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "show/noShow切换", notes = "show/noShow切换（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "旅客名单-show/noShow切换", operDesc = "旅客名单-show/noShow切换")
    @PostMapping("/change-noShow")
    public Result noShow(@RequestBody @Valid CustomOrderTouristNoShowReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.noShow(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "锁定状态切换", notes = "锁定状态切换（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "旅客名单-锁定状态切换", operDesc = "旅客名单-锁定状态切换")
    @PostMapping("/change-lock")
    public Result changeLock(@RequestBody @Valid CustomOrderTouristNoShowReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.changeLock(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "登记", notes = "登记（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "旅客名单-登记", operDesc = "旅客名单-登记")
    @PostMapping("/check-in")
    public Result checkIn(@RequestBody @Valid CustomOrderTouristCheckInReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.checkIn(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "送签", notes = "送签（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "旅客名单-送签", operDesc = "旅客名单-送签")
    @PostMapping("/send-visa")
    public Result sendVisa(@RequestBody @Valid CustomOrderTouristSendVisaReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.sendVisa(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "出签成功", notes = "出签成功（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "旅客名单-出签成功", operDesc = "旅客名单-出签成功")
    @PostMapping("/sign-out-success")
    public Result signOutSuccess(@RequestBody @Valid CustomOrderTouristSignOutSuccessReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.signOutSuccess(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "旅客名单列表" , notes = "旅客名单列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅客名单列表", operDesc = "旅客名单列表")
    @PostMapping("/nameList")
    public Result<PageResponse<CustomOrderTouristNameListDTO>> list(@RequestBody CustomOrderTouristNameListReq touristNameListReq){
        try {
            return Result.success(orderTouristInfoService.nameList(touristNameListReq));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }
    
    @ApiOperation(value = "旅客分组列表" , notes = "旅客分组列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅客分房分组列表", operDesc = "旅客分房分组列表")
    @PostMapping("/groupList")
    public Result<PageResponse<CustomOrderTouristRoomGroupDTO>> groupList(@RequestBody CustomOrderTouristRoomReq roomReq){
        try {
            return Result.success(orderTouristInfoService.queryList(roomReq));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "旅客分房查询" , notes = "旅客分房查询")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅客分房查询", operDesc = "旅客分房查询")
    @PostMapping("/roomList")
    public Result<List<CustomOrderTouristRoomDTO>> query(@RequestBody CustomOrderTouristRoomReq roomReq){
        try {
            List<CustomOrderTouristRoomDTO> result = orderTouristInfoService.roomList(roomReq);
            return Result.success(result);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }
    
    @ApiOperation(value = "游客分组", notes = "游客分组")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "游客分组", operDesc = "游客分组")
    @PostMapping("/group")
    public Result group(@RequestBody @Valid CustomRoomGroupReq roomGroupReq){
        try {
            roomGroupReq.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristInfoService.group(roomGroupReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "游客分房", notes = "游客分房")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "游客分房", operDesc = "游客分房")
    @PostMapping("/room")
    public Result room(@RequestBody CustomRoomRoomReq roomReq){
        try {
            return orderTouristInfoService.updateRoom(roomReq,getCurrentUser(getRequest()).getId());
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "旅客名单旅行团信息", notes = "旅客名单旅行团信息")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "旅行团数据", operDesc = "旅行团数据")
    @GetMapping("/tourist/{id}")
    public Result<CustomGroupTouristInfoDTO> groupInfo(@PathVariable Long id){
        try {
            return Result.success(orderTouristInfoService.groupInfo(id));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }
    
    @ApiOperation(value = "旅客名单获取组信息", notes = "根据团期id查询组信息")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "根据团期id查询组信息", operDesc = "根据团期id查询组信息")
    @GetMapping("/queryGroup/{id}")
    public Result<List<CustomOrderTouristGroupDTO>> queryGroup(@PathVariable Long id){
        try {
            return orderTouristInfoService.queryGroup(id);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "新增游客分组", notes = "新增游客分组")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "新增游客分组", operDesc = "新增游客分组")
    @GetMapping("/addGroup/{scheduleId}")
    public Result addGroup(@PathVariable Long scheduleId){
        try {
            return orderTouristInfoService.addGroup(scheduleId,getCurrentUser(getRequest()).getId());
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "旅客名单-导出分组", notes = "旅客名单-导出分组（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "旅客名单-导出分组", operDesc = "旅客名单-导出分组")
    @PostMapping("/export-group")
    public void exportGroup(@RequestBody @Valid TripScheduleInfoReq req){
        ExcelData data = orderTouristInfoService.exportGroup(req);
        if (data == null){
            throw new BusinessException(SystemError.FINANCE_BILL_17023);
        }
        try {
            ExportExcelUtils.exportExcel(getResponse(),"旅客分组.xlsx",data);
        }catch (Exception e){
            throw new BusinessException(SystemError.SYS_437);
        }
    }

    @ApiOperation(value = "旅客名单-导出分房", notes = "旅客名单-导出分房（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "旅客名单-导出分房", operDesc = "旅客名单-导出分房")
    @PostMapping("/export-room")
    public void exportRoom(@RequestBody @Valid TripScheduleInfoReq req){
        ExcelData data = orderTouristInfoService.exportRoom(req);
        if (data == null){
            throw new BusinessException(SystemError.FINANCE_BILL_17023);
        }
        try {
            ExportExcelUtils.exportExcel(getResponse(),"旅客分房.xlsx",data);
        }catch (Exception e){
            throw new BusinessException(SystemError.SYS_437);
        }
    }

    @ApiOperation(value = "旅客名单-导出名单", notes = "旅客名单-导出名单（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "旅客名单-导出名单", operDesc = "旅客名单-导出名单")
    @PostMapping("/export-tourist")
    public void exportTourist(@RequestBody @Valid TripScheduleInfoReq req){
        ExcelData data = orderTouristInfoService.exportTourist(req);
        if (data == null){
            throw new BusinessException(SystemError.FINANCE_BILL_17023);
        }
        try {
            ExportExcelUtils.exportExcel(getResponse(),"旅客名单.xlsx",data);
        }catch (Exception e){
            throw new BusinessException(SystemError.SYS_437);
        }
    }

    @ApiOperation(value = "导入旅客名单", notes = "导入旅客名单（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "导入旅客名单", operDesc = "导入旅客名单")
    @PostMapping("/export-in")
    public Result exportIn(@RequestPart("file") MultipartFile file, @RequestParam("order_id") Long orderId) {
        try {
            if (file.isEmpty()){
                throw new BusinessException(SystemError.SYS_409,"file");
            }
            List<ExcelTemp> tempList = new ArrayList<>();
            Workbook wb0 = null;
            InputStream inputStream = null;
            try {
                //文件后缀名
                String fileExtension = getFileExtension(file.getOriginalFilename());
                inputStream = file.getInputStream();
                //根据指定的文件输入流导入Excel从而产生Workbook对象
                if ("xls".equals(fileExtension)){
                    wb0 = new HSSFWorkbook(inputStream);
                }else if ("xlsx".equals(fileExtension)){
                    wb0 = new XSSFWorkbook(inputStream);
                }
                if (wb0 != null){
                    //获取Excel文档中的第一个表单
                    Sheet sht0 = wb0.getSheetAt(0);
                    //对Sheet中的每一行进行迭代
                    for (Row r : sht0) {
                        //如果当前行的行号（从0开始）未达到2（第三行）则从新循环
                        if (r.getRowNum() < 2) {
                            continue;
                        }
                        //设置单元格类型
                        Cell cell1 = r.getCell(0);
                        cell1.setCellType(CellType.STRING);
                        Cell cell2 = r.getCell(1);
                        cell2.setCellType(CellType.STRING);
                        Cell cell3 = r.getCell(2);
                        cell3.setCellType(CellType.STRING);
                        Cell cell4 = r.getCell(3);
                        cell4.setCellType(CellType.STRING);
                        Cell cell5 = r.getCell(4);
                        cell5.setCellType(CellType.STRING);
                        Cell cell6 = r.getCell(5);
                        cell6.setCellType(CellType.STRING);
                        Cell cell7 = r.getCell(6);
                        cell7.setCellType(CellType.STRING);
                        Cell cell8 = r.getCell(7);
                        cell8.setCellType(CellType.STRING);
                        Cell cell9 = r.getCell(8);
                        cell9.setCellType(CellType.STRING);
                        Cell cell10 = r.getCell(9);
                        cell10.setCellType(CellType.STRING);
                        Cell cell11 = r.getCell(10);
                        cell11.setCellType(CellType.STRING);
                        Cell cell12 = r.getCell(11);
                        cell12.setCellType(CellType.STRING);
                        Cell cell13 = r.getCell(12);
                        cell13.setCellType(CellType.STRING);
                        Cell cell14 = r.getCell(13);
                        cell14.setCellType(CellType.STRING);
                        Cell cell15 = r.getCell(14);
                        cell15.setCellType(CellType.STRING);
                        Cell cell16 = r.getCell(15);
                        cell16.setCellType(CellType.STRING);
                        Cell cell17 = r.getCell(16);
                        cell17.setCellType(CellType.STRING);
                        Cell cell18 = r.getCell(17);
                        cell18.setCellType(CellType.STRING);
                        Cell cell19 = r.getCell(18);
                        cell19.setCellType(CellType.STRING);
                        Cell cell20 = r.getCell(19);
                        cell20.setCellType(CellType.STRING);
                        Cell cell21 = r.getCell(20);
                        cell21.setCellType(CellType.STRING);
                        Cell cell22 = r.getCell(21);
                        cell22.setCellType(CellType.STRING);
                        Cell cell23 = r.getCell(22);
                        cell23.setCellType(CellType.STRING);
                        Cell cell24 = r.getCell(23);
                        cell24.setCellType(CellType.STRING);
                        Cell cell25 = r.getCell(24);
                        cell25.setCellType(CellType.STRING);
                        Cell cell26 = r.getCell(25);
                        cell26.setCellType(CellType.STRING);
                        Cell cell27 = r.getCell(26);
                        cell27.setCellType(CellType.STRING);
                        Cell cell28 = r.getCell(27);
                        cell28.setCellType(CellType.STRING);
                        //创建实体类
                        ExcelTemp temp = new ExcelTemp();
                        //封装实体类属性
                        temp.setId(Long.valueOf(cell1.getStringCellValue()));
                        temp.setTouristTypeName(cell2.getStringCellValue());
                        temp.setCnSurname(cell3.getStringCellValue());
                        temp.setCnName(cell4.getStringCellValue());
                        temp.setEnSurname(cell5.getStringCellValue());
                        temp.setEnName(cell6.getStringCellValue());
                        Integer genger = getGenger(cell7.getStringCellValue());
                        temp.setGender(genger);
                        Long nationId = orderTouristInfoService.getNationId(cell11.getStringCellValue());
                        temp.setNationId(nationId);
                        temp.setNation(cell8.getStringCellValue());
                        temp.setMobileAreaCode(cell8.getStringCellValue());
                        temp.setMobile(cell9.getStringCellValue());
                        temp.setBirthday(com.ctshk.common.utils.DateUtil.parse(cell10.getStringCellValue(),"yyyyMMdd"));
                        temp.setEmail(cell12.getStringCellValue());
                        temp.setRemark(cell13.getStringCellValue());

                        Long certificateTypeId1 = orderTouristInfoService.getCertificateTypeId(cell14.getStringCellValue());
                        temp.setCertificateTypeId1(certificateTypeId1);
                        temp.setCertificateType1(cell14.getStringCellValue());
                        temp.setCertificateNumber1(cell15.getStringCellValue());
                        if (StringUtils.isNotBlank(cell16.getStringCellValue())){
                            temp.setCertificateValidDate1(com.ctshk.common.utils.DateUtil.parse(cell16.getStringCellValue(),"yyyyMMdd"));
                        }
                        temp.setCertificatePlace1(cell17.getStringCellValue());

                        Long certificateTypeId2 = orderTouristInfoService.getCertificateTypeId(cell18.getStringCellValue());
                        temp.setCertificateTypeId2(certificateTypeId2);
                        temp.setCertificateType2(cell18.getStringCellValue());
                        temp.setCertificateNumber2(cell19.getStringCellValue());
                        if (StringUtils.isNotBlank(cell20.getStringCellValue())){
                            temp.setCertificateValidDate2(com.ctshk.common.utils.DateUtil.parse(cell20.getStringCellValue(),"yyyyMMdd"));
                        }
                        temp.setCertificatePlace2(cell21.getStringCellValue());

                        Long certificateTypeId3 = orderTouristInfoService.getCertificateTypeId(cell22.getStringCellValue());
                        temp.setCertificateTypeId3(certificateTypeId3);
                        temp.setCertificateType3(cell22.getStringCellValue());
                        temp.setCertificateNumber2(cell23.getStringCellValue());
                        if (StringUtils.isNotBlank(cell24.getStringCellValue())){
                            temp.setCertificateValidDate3(DateUtil.parse(cell24.getStringCellValue(),"yyyyMMdd"));
                        }
                        temp.setCertificatePlace3(cell25.getStringCellValue());

                        temp.setEmergencyContactName(cell26.getStringCellValue());
                        temp.setEmergencyMobileAreaCode(cell27.getStringCellValue());
                        temp.setEmergencyMobile(cell28.getStringCellValue());
                        tempList.add(temp);
                    }
                }
                System.out.println("旅客列表数据 =====>>> " + JSON.toJSONString(tempList));
                return orderTouristInfoService.exportIn(tempList,getCurrentUser(getRequest()).getId(),orderId);
            }catch (Exception e){
                e.printStackTrace();
                throw new BusinessException(SystemError.SYS_437);
            }finally {
                try {
                    inputStream.close();
                }catch (Exception e){
                    throw new BusinessException(SystemError.SYS_437);
                }
            }
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "導出旅客模板", notes = "導出旅客模板（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "導出旅客模板", operDesc = "導出旅客模板")
    @PostMapping("/export-out")
    public void exportOut(@RequestBody @Valid CustomOrderIdReq req) {
        ExcelData data = orderTouristInfoService.exportOut(req);
        if (data == null){
            throw new BusinessException(SystemError.FINANCE_BILL_17023);
        }
        try {
            ExportExcelUtils.exportExcel2(getResponse(),"旅客名单模板.xlsx",data);
        }catch (Exception e){
            throw new BusinessException(SystemError.SYS_437);
        }
    }

    /**
     * 获取文件扩展名(后缀)
     * @param filename
     * @return
     */
    public String getFileExtension(String filename) {
        if (StringUtils.isNotBlank(filename)) {
            String string = filename.trim();
            int index = filename.lastIndexOf(".");
            if (index > 0 && index < string.length() - 1) {
                return string.substring(index + 1);
            }
        }
        return null;
    }

    /**
     * 获取称谓
     * @param str
     * @return
     */
    private Integer getGenger(String str) {
        if ("先生".equals(str)){
            return 1;
        }else if ("女士".equals(str)){
            return 2;
        }else if ("小姐".equals(str)){
            return 3;
        }else if ("男童".equals(str)){
            return 4;
        }else if ("女童".equals(str)){
            return 5;
        }
        return null;
    }

}
